package com.tedu.controller;

import com.tedu.entry.vo.EmpVO;
import com.tedu.service.EmpService;
import com.tedu.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author：毕龙
 * Date: 2023/7/28 17:49
 */
@WebServlet("/emp/add")
public class EmpAddController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.处理请求

        //处理请求的中文乱码
        request.setCharacterEncoding("utf-8");

        String name = request.getParameter("name");
        String salary = request.getParameter("salary");
        String age = request.getParameter("age");
        String birthday = request.getParameter("birthday");
        String deptId = request.getParameter("deptId");
        EmpVO vo = new EmpVO();
        vo.setName(name).setSalary(salary).setAge(age).setBirthday(birthday).setDeptId(deptId);


        //2.调用业务逻辑
        EmpService service = new EmpServiceImpl();
        service.insertEmp(vo);


        //2.跳转
        response.sendRedirect(request.getContextPath()+"/emp/findAll");
    }
}
